<div class="text-center">
    <div class="vote-image">
        <img class="img-thumbnail" style="width: 200px; " src="<?php echo $vote['vote_image']; ?>">
    </div>
    <h3 class="vote-name"> <?php echo $vote['vote_name']; ?></h3>
    <div class="desc" style="margin: 0;"><?php echo $vote['vote_desc']; ?></div>
    <div class="vote-data" style="padding: 10px;">
        <span class="vote-count" style="color: #f00;font-size: 23px;" id="vote_count"><?php echo $vote['vote_count']; ?></span>
        <span class="vote-info">人气</span>
    </div>
    <div class="qr-code" style="padding-bottom: 10px;">
        <img src="https://api.dev.suixinlv.cn/qrcode/?data=<?php echo urlencode(SITE_URL.'/vote/item?id='.$vote['vote_id'])?>&size=6" alt="">
    </div>
    <div class="c" style="padding-bottom: 10px;">
        <button vote-data="support?id=<?php echo $vote['vote_id']; ?>" <?php echo $is_voted?'disabled="disabled"':'';?>
                class="btn btn-primary btn-block btn-lg btn-vote"><?php echo $is_voted?'已点赞':'为它点赞';?></button>
    </div>
    <section class="vote-history">
        <h3 class="text-left hide">点赞记录</h3>
        <ul class="vote-list">
            <?php
                if(count($vote_history) == 0){
                    echo '<li style="text-center">暂时还没有人为此作品点赞</li>';
                }
            ?>
            <?php foreach ($vote_history as $h): ?>
            <li class="vote-list-item  text-left" style="vertical-align: baseline">
                <?php
                echo '<span style="color: #f00;">';
                if($h['user_name']) {
                    echo $h['user_name'];
                }else if($h['student_no']) {
                    echo $h['student_no'];
                }else if($h['phone']) {
                    echo substr($h['phone'],0,3).'****'.substr($h['phone'],6,4);
                }else{
                    echo '微信用户_'.$h['user_open_id'];
                }
                echo "</span> 于 ".substr($h['created_at'],0,16)." 为此作品点赞<span style=\"color: #f00;font-size: 16px;\"> {$h['vote_count']} </span>次";
                ?>
            </li>
            <?php endforeach; ?>
        </ul>
    </section>
</div>
<script>
    $(function () {
        $('button.btn-vote').on('click',function(){
            var btn = $(this);
            if(btn.attr('disabled')) return false;
            btn.attr('disabled','disabled');
            btn.text('点赞...');
            $.post(btn.attr('vote-data'),function (ret) {
                if(ret['code'] == 0){
                    btn.text('已点赞');
                    $('#vote_count').text(ret['data']['count']);
                    return false;
                }else if(ret['code'] == 302){
                    location.href = ret['data'];
                    return false;
                }
                btn.removeAttr('disabled').text('为它点赞');
                alert(ret['message']);
            },'json').fail(function () {
                btn.removeAttr('disabled').text('为它点赞');
                alert('点赞失败,请重试!');
            });
            return false;
        });
    })
</script>